package com.yanqu.road.server.cmd.activity.specialcookboy;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.specialcookboy.SpecialCookBoyProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.connect.CrossAgentLinkedControl;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = CrossProtocol.C_SPECIAL_COOK_BOY_USE_CODE_REQ_GAME_TO_CROSS, desc = "小当家使用分享码区服转发上跨服,跨服转发到目标区服")
public class CrossSpecialCookBoyUseCodeReqCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        SpecialCookBoyProto.SpecialCookBoyUseCodeReqGameToCross reqGameToCross = SpecialCookBoyProto.SpecialCookBoyUseCodeReqGameToCross.parseFrom(yanQuMessage.getBytes());
        SpecialCookBoyProto.SpecialCookBoyUseShareCodeReqFromOtherServer.Builder builder = SpecialCookBoyProto.SpecialCookBoyUseShareCodeReqFromOtherServer.newBuilder();

        builder.setFromServerId(CrossAgentLinkedControl.getLinkedClient(ctx).getServerId());
        builder.setFromUserId(yanQuMessage.getPlayerId());
        builder.setCode(reqGameToCross.getCode());
        builder.setTargetUserId(reqGameToCross.getTargetUserId());
        //发去目标区服
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_SPECIAL_COOK_BOY_USE_SHARE_CODE_REQ_FROM_OTHER_SERVER, builder);
        MessageHelper.sendPacket(reqGameToCross.getTargetServerId(), 0, message);

    }
}
